var interface_url_prefix = "http://appapi.nmgnews.com.cn/";
// var interface_url_prefix = "http://appapi.people.com.cn";
// var source_url_prefix = "http://rmrbimg2.people.cn/data/rmrbwap";
var source_url_prefix = "http://appimg.nmgnews.com.cn/data/nmgwap";
var wx_url_prefix = "http://appapi.nmgnews.com.cn/";
var client_ver = '5.1.1';

$(function() {
    appActions.init();
    //所有#链接取消默认动作
    $("body").on("click","a[href='#']",function(e){
        stopDefault( e );
    });

    //微信分享
    new WxShare();

    //初始化推荐阅读
    (new Recommend()).init();

    //初始化热门评论
    (new Comment()).init();

    //初始化下载模块
    (new Download()).init();

    //判断浏览器是否支持多行省略的css属性:line-clamp
    if(!isSupportCss("line-clamp")) {
        clampText(".clamp");
    }

    //去除图片缩进
    $(".article p").has("img").css("textIndent", "0em");

    //直播间
    (new LiveRoom()).init();
    //统计
    (new Statistics()).init();
});

/**设置html上的基准字体大小*/
function setRootSize() {
    var docEl = document.documentElement || document.body,
        resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
        recalc = function () {
            var clientWidth = docEl.clientWidth;
            if (!clientWidth) return;
            docEl.style.fontSize = 100 * (clientWidth / 320) + 'px';
        };
    if (!document.addEventListener) return;
    window.addEventListener(resizeEvt, recalc, false);
    document.addEventListener('DOMContentLoaded', recalc, false);
}

/**计算字符串的字节长度*/
function byteLength(string, n) {
    n = n || 2;
    return string.replace(/[^\x00-\xff]/g,({1:"a",2:"aa"})[n]).length;
}

/**阻止浏览器的默认行为*/
function stopDefault(e) {
    if(e && e.preventDefault) {
        //w3c
        e.preventDefault();
    }
    else {
        //ie
        window.event.returnValue = false;
    }
    return false;
}

/**
 * 加载js文件
 * @param {string} url
 * @param {function} callback
 */
function loadScript(url, callback, scope) {
    scope = scope || window;
    var node = document.createElement('script');
    node.onload = node.onreadystatechange = function() {
        var rs=node.readyState;
        if('undefined'===typeof rs || 'loaded'===rs || 'complete'===rs){
            try{
                callback && callback.apply(scope);
            }finally{
                node.onload=node.onreadystatechange=null;
                node=null;
            }
        }
    };
    node.async=true;
    node.charset='utf-8';
    node.src=url;
    (document.head || document.documentElement).appendChild(node);
}

/**
 * 用浏览器内部转换器实现html解码
 */
function htmlDecode(text) {
    var temp = document.createElement("div");
    temp.innerHTML = text;
    var output = temp.innerText || temp.textConent;
    temp = null;
    return output;
}

/**判断字符串是否为空*/
function isEmptyStr(str) {
    if(!str || str == 'null' || str == 'undefined') {
        return true;
    }
    return false;
}

/**判断对象是否为空*/
function isEmptyObj(obj) {
    for(var name in obj) {
        return false;
    }
    return true;
}

/**js判断浏览器是否支持某个css属性*/
function isSupportCss(propertyName) {
    var prefix = ["webkit", "moz", "ms", "o", ""];
    var humpStr = [];
    var htmlStyle = document.documentElement.style;
    var _toHumb = function(str) {
        return str.replace(/-(\w)/g, function($0, $1) {
            return $1.toUpperCase();
        });
    };
    var i ;
    for(i in prefix) {
        humpStr.push(_toHumb(prefix[i] + "-" + propertyName));
    }
    for(i in humpStr) {
        if(humpStr[i] in htmlStyle) {
            return true;
        }
    }
    return false;
}

/**将超出范围的文字以...代替*/
function clampText(selector, opts) {
    selector = selector || ".clamp";
    opts = $.extend({"wrap": "letter"}, opts);
    $(selector).dotdotdot(opts);
}

/**判断是否是微信*/
function isWx() {
    var ua = navigator.userAgent.toLowerCase();
    if(ua.match(/MicroMessenger/i) == "micromessenger") {
        return true;
    }
    else {
        return false;
    }
}

/**微信分享*/
function WxShare() {
    if(window.shareData) {
        var title = htmlDecode(shareData.title);
        var desc = htmlDecode(shareData.desc);
        var imgUrl = shareData.img_url;
        if(isEmptyStr(imgUrl) || !/.(png|jpg|gif|bmp)$/.test(imgUrl)) {
            imgUrl = source_url_prefix + '/css/images/share_logo.png';
        }
        this.imgUrl = imgUrl;
        this.shareTitle = title;
        this.descContent = isEmptyStr(desc) ? '您的专属时政平台' : desc;
//      this.lineLink = shareData.link;
        this.lineLink = shareData.link.substring(0, 4) ==='http' ? shareData.link : window.location.href.split("?")[0];
        this.initWx();
        this.onReady();
    }
}

WxShare.prototype = {
    initWx: function() {
        var curUrl = window.location.href.split("#")[0];
        curUrl = encodeURIComponent(curUrl);
        $.ajax({
            type: "get",
            url: wx_url_prefix+"/static/weixin/jssdk.php?url="+curUrl,
            dataType : "jsonp",
            jsonp: "callback",
            jsonpCallback:"success_jsonpCallback",
            success: function(data) {
                wx.config({
                    // debug:true,
                    appId: data.appId,
                    timestamp: data.timestamp,
                    nonceStr: data.nonceStr,
                    signature: data.signature,
                    jsApiList: [
                        "onMenuShareTimeline",
                        "onMenuShareAppMessage"
                    ]
                });
            },
            error: function(data) {

            }
        });
    },
    onReady: function() {
        var me = this;
        wx.ready(function() {
            wx.onMenuShareAppMessage({
                title: me.shareTitle,
                desc: me.descContent,
                // desc: '有品质的新闻',
                link: me.lineLink,
                imgUrl: me.imgUrl,
                success: function() {}
            });
            wx.onMenuShareTimeline({
                title: me.shareTitle,
                link: me.lineLink,
                imgUrl: me.imgUrl,
                success: function() {}
            });
        });
    }
};

var appActions = {
    /**0:普通, 1:android, 2:ios*/
    webInOs: 0,
    /**屏幕分辨率*/
    device_size: "480x320",
    init: function() {
        var u = navigator.userAgent;
        if((u.indexOf('Android') > -1 || u.indexOf('Linux') > -1)) {
            appActions.webInOs = 1;
        }
        else if(!!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)) {
            appActions.webInOs = 2;
        }
        else {
            appActions.webInOs = 0;
        }
        var dpr = window.devicePixelRatio ;
        var sw = window.screen.width * dpr;
        if(sw >= 480 && sw < 800) {
            appActions.device_size = '640x360';
        }
        else if(sw >= 800) {
            appActions.device_size = '800x480';
        }

        appActions.initRequestParams();
    },
    initRequestParams: function() {
        var Request = GetRequest();
        detailData['id_3'] = detailData['id_3'] || Request['articleid'];
        detailData['category_id'] = detailData['category_id'] || Request['categoryid'];
        detailData['news_link'] = detailData['news_link'] || Request['newslink'];
        detailData['articletype'] = detailData['articletype'] || Request['articletype'];
        detailData['title'] = detailData['articletype'] || Request['title'];
        detailData['isGovDetail'] = detailData['isGovDetail'] || Request['isGovDetail'] || 0;
    }
};

/**获取url参数*/
function GetRequest() {
    var url = location.search;
    var theRequest = new Object();
    if (url.indexOf("?") != -1) {
        var str = url.substr(1);
        strs = str.split("&");
        for(var i = 0; i < strs.length; i ++) {
            theRequest[strs[i].split("=")[0]]= unescape(strs[i].split("=")[1]);
        }
    }
    return theRequest;
}

/**评论交互模块*/
function Comment() {
}

Comment.prototype = {
    /**初始化入口*/
    init: function() {
        this.initEvents();
        if($("#comment").length > 0) {
            this.initHotComments();
        }
        if($('#oneComment').length > 0) {
            this.initOneComment();
        }
    },
    /**初始化事件*/
    initEvents: function() {
        var me = this, $body = $("body");
        //初始化展开回复事件
        $body.on("click", "#comment .open_all, #oneComment .open_all", $.proxy(me.openAll, me));

        //初始化展开评论内容事件
        $body.on("click", "#comment .toggle_btn_wrap a, #oneComment .toggle_btn_wrap a", $.proxy(me.openDetail, me));
    },
    /**初始化单条精彩评论*/
    initOneComment: function() {
        var me = this;
        var Request = new Object();
        Request = GetRequest();
        if(Request["commentid"] && Request["commentid"]!=""){
            var commentid = Request["commentid"];
            var ajaxUrl = interface_url_prefix+"/comments/getcommentbyid?commentid="+commentid+"&client_ver="+client_ver;
            $.ajax({
                type : "GET",
                cache:false,
                url : ajaxUrl,
                dataTyp:"json",
                success : function (json) {
                    if(typeof(json)=="string"){
                        json = JSON.parse(json).data;
                    }else{
                        json = json.data;
                    }
                    if(!isEmptyObj(json)){
                        if(json.article_title) {
                            document.title = json.article_title;
                            //hack在微信等webview中无法修改document.title的情况
                            var $body = $('body');
                            var $iframe = $('<iframe src="./css/images/logo_share.png" class="none"></iframe>').on('load', function() {
                                setTimeout(function() {
                                    $iframe.off('load').remove();
                                }, 0);
                            }).appendTo($body);
                        }
                        window.shareData = {
                            img_url: source_url_prefix + '/css/images/comment_logo.png',
                            title: json.article_title,
                            desc: json.content,
                            link: window.location.href.split("?")[0] + '?commentid='+commentid
                        };
                        //微信分享
                        new WxShare();
                        var html = template('oneComment', json);
                        $("#oneComment").html(html);
                        me.resetCommentHeight();
                    }
                }
            });
        }
    },
    /**初始化热门评论*/
    initHotComments: function() {
        var me = this, count = 5;
        var Request = new Object();
        Request = GetRequest();
        var ajaxUrl = interface_url_prefix+"/comments/hotcomments?articleid="+detailData.id_3+"&count="+count+"&client_ver="+client_ver;
        if(Request["articleid"] && Request["articleid"]!="") {
            var articleid = Request["articleid"];
            detailData.id_3 = articleid;
            ajaxUrl = interface_url_prefix+"/comments/getdetailcomments?articleid="+detailData.id_3;
        }
        else if(Request["id"] && Request["id"] != "") {
            var articleid = Request["id"];
            detailData.id_3 = articleid;
            var pageData = window.pageData;
            var pageType = pageData ? pageData.pageType : '';
            var queryId = articleid;
            if(pageType == "ask_detail") {
                queryId = queryId + "_ask_" + queryId;
            }
            else if(pageType == "ask_topic") {
                queryId = queryId + "_asktopic_" + queryId;
            }
            ajaxUrl = interface_url_prefix+"/comments/hotcomments?articleid="+queryId+"&count="+3+"&client_ver="+client_ver;
        }
        var $comment = $('#comment');
        //异步获取评论数据
        $.ajax({
            type: "GET",
            cache: false,
            url: ajaxUrl,
            dataType: "json",
            success: function(json) {
                var json = json.data;
                if(json && json.comments && json.comments.length > 0) {
                    var pageData = window.pageData;
                    var pageType = pageData ? pageData.pageType : '';
                    var dataObj = {commentsList: json.comments, count: json.count, pageType: pageType};
                    var html = template('hotComments', dataObj);
                    $comment.prepend(html);//加到了后台模板里面
                    $('#more_comment a').html('打开内蒙古日报，查看全部评论');
                    me.resetCommentHeight();
                }
                else {
                    $comment.remove();
                }
            }
        });
    },
    /**展开评论内容*/
    openDetail: function(e) {
        stopDefault(e);
        var $target = $(e.currentTarget);
        if($target.hasClass("open_text_btn")) {
            $target.parent().parent(".comment_closeing").removeClass("comment_closeing").addClass("comment_opening");
            $target.removeClass("open_text_btn").addClass("close_text_btn").find(".t").text("收起");
        }
        else {
            $target.parent().parent(".comment_opening").removeClass("comment_opening").addClass("comment_closeing");
            $target.removeClass("close_text_btn").addClass("open_text_btn").find(".t").text("展开");
        }
    },
    /**展开全部评论*/
    openAll: function(e) {
        stopDefault(e);
        var $target = $(e.currentTarget);
        $target.hide();
        $target.parents(".reply_con").addClass("show_all");
    },
    resetCommentHeight: function() {
        $(".comment_block .con_text_wrap").each(function() {
            var $this = $(this);
            var innerH = $this.find(".con_text").height();
            var outerH = $this.height();
            if(innerH - outerH > (outerH/3 - 1)) {
                $this.parent().addClass("comment_closeing");
            }
        });
    }
};

/**下载模块*/
function Download() {
    this.$top = $('#down_top_wrap');
    this.$more = $("#more_comment");
    this.$guid = $("#opensafari");
    this.detailData = detailData;
}

Download.prototype = {
    /**初始化入口*/
    init: function() {
        var detailData = this.detailData;
        if((this.$top.length > 0 || this.$more.length > 0) && detailData) {
            this.downLink = this.$top.find("a").attr("href")
            this.appLink = "fujiandailynewsdetail://open?news_id="+detailData.id+"&news_type="+detailData.type+"&tagid="+detailData.tagid+"&redirect_type="+detailData.redirect_type+"&redirect_url="+detailData.redirect_url
                            +"&id_3="+detailData.id_3+"&category_id="+detailData.category_id+"&news_link="+detailData.news_link+"&articleType="+detailData.articletype+"&title="+detailData.title+"&isGovDetail="+detailData.isGovDetail;

            if(appActions.webInOs == 1) {
                $("body").addClass("android");
            }

            this.initEvents();

            //自动加载app
            this.openAppFn();
        }

    },
    /**初始化事件*/
    initEvents: function() {
        var me = this;
        this.$top.on("click", $.proxy(me.downFn, me));
        this.$more.on("click", $.proxy(me.downFn, me));
        this.$guid.on("click", $.proxy(me.hideFn, me));
    },
    /**跳转app*/
    openAppFn: function() {
        var iframe = document.createElement("iframe");
        iframe.style.display = "none";
        iframe.src = this.appLink;
        var cb = function() {
            if(iframe == null) {
                return;
            }
            iframe.onload = iframe.onerror = iframe.onreadystatechange = null;
            iframe.src = "";
            iframe.parentNode.removeChild(iframe);
            iframe = null;
        };
        iframe.onload = iframe.onerror = iframe.onreadystatechange = cb;
        document.getElementsByTagName("body")[0].appendChild(iframe);
        setTimeout(function() {
            cb();
        },40);
        //zhushi
        // alert(this.appLink);
        // window.open("sxdailynewsdetail://open");
    },
    /**跳转下载页*/
    downFn: function(e) {
        var me = this;
        stopDefault(e);
        if(isWx()) {
            $("#opensafari").addClass("show");
            $("html, body").css({"overflow-y": "hidden", "height": "100%"});
            return false;
        }
        me.openAppFn();
        setTimeout(function() {
            window.location.href = me.downLink;
        }, 500);
        return false;
    },
    /**隐藏引导图*/
    hideFn: function() {
        this.$guid.removeClass("show");
        $("html, body").css({"overflow-y": "auto", "height": "auto"});
    }
};

/**直播间模块*/
function LiveRoom() {

}

LiveRoom.prototype = {
    topId: null,
    /**初始化入口*/
    init: function() {
        if($(".responsiveTabs").length > 0) {
            this.maxId = null;
            this.live_type = $(".responsiveTabs .tabs a").attr("data-live_type");
            this.articleId = detailData.id_3;
            this.loadCount = 5;
            this.ajaxUrl = interface_url_prefix+"/live/live?live_type="+this.live_type+"&articleid="+this.articleId+"&count="+this.loadCount+"&device_size="+appActions.device_size+"&client_ver="+client_ver;
            if(!window.template) {
                loadScript(source_url_prefix+'/tpl/build/template.js', this.initData, this);
            }
            else {
                this.initData();
            }
            this.initEvents();
        }
    },
    /**初始化事件*/
    initEvents: function() {
        var me = this, $body = $("body");
        $body.on('click', '.toggle_btn_wrap a', $.proxy(me.openText, me));

        $body.on('click', '.toggle_top_btn', $.proxy(me.toggleTop, me))
    },
    /**初始化数据*/
    initData: function() {
        var me = this;
        $('.tabs_item_ul').html('');
        $.ajax({
            type: 'GET',
            url: me.ajaxUrl,
            dataType: 'json',
            success: function(json) {
                var comments = json.data.comments;
                if(comments && comments.length > 0) {
                    me.maxId = comments[comments.length - 1].comment_id;
                    me.formatData(comments);
                    me.loadMore();
                }
            }
        });
    },
    formatData: function(comments) {
        var me = this, tops = [];
        for(var i = 0; i < comments.length; i++) {
            if(comments[i].istop+"" == "true") {
                if(comments[i].comment_id != me.topId) {
                    me.topId = comments[i].comment_id;
                    tops.push(comments[i]);
                }
                comments.splice(i, 1);
                break;
            }
        }
        if(tops.length > 0) {
            var topHtml = template('liveRoom', {comments: tops});
            me.formatText(topHtml, 'top');
        }

        if(comments.length > 0) {
            var normalHtml = template('liveRoom', {comments: comments});
            me.formatText(normalHtml, 'normal');
        }
    },
    /**超出3行显示...*/
    formatText: function(html, type) {
        var $context = null;
        if(type === 'top') {
            var $top = $('.tabs_item_ul .top');
            if($top.length == 0) {
                $context = $(html).appendTo('.tabs_item_ul').find('.item_comment');
            }
            else {
                $context = $top.replaceWith(html).find('.item_comment');
            }
        }
        else {
            $context = $(html).appendTo('.tabs_item_ul').find('.item_comment');
        }
        this.resetCommentHeight($context);
    },
    toggleTop: function() {
        var $btn = $('.toggle_top_btn');
        if($btn.hasClass("open")) {
            $btn.removeClass("open");
            $(".top").css("height", "auto");
            $(".top .inner_wrap").removeClass("none");
        }
        else {
            $btn.addClass("open");
            $(".top").css("height", "0.2rem");
            $(".top .inner_wrap").addClass("none")
        }
    },
    resetCommentHeight: function($context) {
        $context.find(".con_text_wrap").each(function() {
            var $this = $(this);
            var innerH = $this.find(".con_text").height();
            var outerH = $this.height();
            if(innerH - outerH > (outerH/3 - 1)) {
                $this.parent().addClass("comment_closeing");
            }
        });
    },
    /**展开内容*/
    openText: function(e) {
        stopDefault(e);
        var $target = $(e.currentTarget);
        if($target.hasClass("open_text_btn")) {
            $target.parent().parent(".comment_closeing").removeClass("comment_closeing").addClass("comment_opening");
            $target.removeClass("open_text_btn").addClass("close_text_btn").find(".t").text("收起");
        }
        else {
            $target.parent().parent(".comment_opening").removeClass("comment_opening").addClass("comment_closeing");
            $target.removeClass("close_text_btn").addClass("open_text_btn").find(".t").text("展开");
        }
    },
    /**上拉加载更多*/
    loadMore: function() {
        var me = this;
        $('body').pullload({
            domUp : {
                domClass   : 'pullload-up',
                domRefresh : '<div class="pullload-refresh">↓下拉刷新</div>',
                domUpdate  : '<div class="pullload-update">↑释放更新</div>',
                domLoad    : '<div class="pullload-load"><span class="loading"></span>加载中...</div>'
            },
            domDown : {
                domClass   : 'pullload-down',
                domRefresh : '<div class="pullload-refresh">↑上拉加载更多</div>',
                domUpdate  : '<div class="pullload-update">↓释放加载</div>',
                domLoad    : '<div class="pullload-load"><span class="loading"></span>加载中...</div>'
            },
            pullUpFn: function(scope) {
                $.ajax({
                    type: 'GET',
                    url: me.ajaxUrl+'&maxid='+me.maxId,
                    dataType: 'json',
                    success: function(json) {
                        var comments = json.data.comments;
                        if(comments && comments.length > 0) {
                            if(comments.length == 1 && comments[0].istop+"" == "true" && comments[0].comment_id == me.topId) {
                                scope.$domResult.html('已无更多数据！');
                            }
                            else {
                                me.maxId = comments[comments.length - 1].comment_id;
                                me.formatData(comments);
                            }
                        }
                        else {
                            scope.$domResult.html('已无更多数据！');
                        }
                        scope.resetLoad();
                    },
                    error: function() {
                        scope.$domResult.html('数据无法加载！');
                        scope.resetLoad();
                    }
                });
            }
        });
    }
};

/**推荐阅读模块*/
function Recommend() {

}

Recommend.prototype = {
    /**初始化入口*/
    init: function() {
        if($('#recommend').length > 0) {
            this.ajaxUrl = interface_url_prefix+'/content/itemrecommend?articleid='+detailData.id_3+"&device_size="+appActions.device_size;
            this.initRecommends();
        }
    },
    /**初始化推荐阅读列表*/
    initRecommends: function() {
        var me = this;
        $.ajax({
            type : "GET",
            cache:false,
            url : me.ajaxUrl,
            dataTyp:"json",
            success : function (json) {
                if(json && json.data && json.data.length > 0) {
                    var html = template('recommend', {relations: json.data});
                    $('#recommend').html(html);
                }
                else {
                    $('#recommend').hide();
                }
            }
        });
    }
}

/**统计模块*/
function Statistics() {
    this.ajaxUrl = interface_url_prefix+'/views/counts?articleid=';
}

Statistics.prototype = {
    init: function() {
        if($("#love").length > 0) {
            this.getCounts_love();
        }
        if($("#interview .topPic").length > 0) {
            this.getCounts_page_zb();
        }
        // if($("#recommend").length > 0) {
        //     this.getCounts_tjyd();
        // }
        if($(".latestNews").length > 0) {
            this.getCounts_zxxw();
        }
        if($(".pubActivities").length > 0) {
            this.getCounts_gyhd();
        }
    },
    /**获取推荐阅读的评论数*/
    getCounts_tjyd: function() {
        var articleids = [];
        var $block = $('#recommend .relat_post');
        var $liEls = $block.find('li');
        $liEls.each(function() {
            var id = $(this).attr('data-articleid');
            articleids.push(id);
        });
        this.ajaxRequest(articleids.join(','), function(data) {
            data = data || [];
            var id = '';
            $.each(data, function(i, e) {
                id = e.articleid;
                e.num = e.num || 0;
                if(e.type == 'comment' && parseInt(e.num) > 0) {
                    $block.find('li[data-articleid^='+id+'] .com_num').text(e.num + ' 评');
                }
            });
        });
    },
    /**获取最新新闻的评论数*/
    getCounts_zxxw: function() {
        var articleids = [];
        var $block = $('.latestNews .relat_post');
        var $liEls = $block.find('li');
        $liEls.each(function() {
            var id = $(this).attr('data-articleid');
            articleids.push(id);
        });
        this.ajaxRequest(articleids.join(','), function(data) {
            data = data || [];
            var id = '';
            $.each(data, function(i, e) {
                id = e.articleid;
                e.num = e.num || 0;
                if(e.type == 'comment'  && parseInt(e.num) > 0) {
                    $block.find('li[data-articleid^='+id+'] .com_num').text(e.num + ' 评');
                }
            });
        });
    },
    /**获取公益活动的爱心数*/
    getCounts_gyhd: function() {
        var articleids = [];
        var $block = $('.pubActivities ul');
        var $liEls = $block.find('li');
        $liEls.each(function() {
            var id = $(this).attr('data-articleid');
            articleids.push(id);
        });
        this.ajaxRequest(articleids.join(','), function(data) {
            data = data || [];
            var id = '';
            $.each(data, function(i, e) {
                id = e.articleid;
                if(e.type == 'like') {
                    $block.find('li[data-articleid^='+id+'] .count').text(e.num || 0);
                }
            });
        });
    },
    /**获取帮页面献爱心数量*/
    getCounts_love: function() {
        var $count = $('#love .count');
        var $status = $('#love .colTip');
        var map = {'1':'募集中...', '2':'募集结束', '3':'募集反馈'};
        var num_old = $count.find('b').html();
        var arrNum = num_old.toString().split('');
        var str = '';
        $.each(arrNum, function(i, e) {
            str += '<b>'+e+'</b>';
        });
        $count.html(str);
        var articleid = detailData.id_3 + '_' + detailData.articletype;
        this.ajaxRequest(articleid, function(data) {
            data = data || [];
            for(var i = 0; i < data.length; i++) {
                if(data[i].type == 'like') {
                    arrNum = data[i].num.toString().split('');
                    str = '';
                    $.each(arrNum, function(i, e) {
                        str += '<b>'+e+'</b>';
                    });
                    $count.html(str);
                }
                else if(data[i].type == 'helpstatus') {
                    if(map[data[i].num]) {
                        $status.html(map[data[i].num]);
                    }
                }
            }
        });
    },
    /**获取直播状态*/
    getCounts_page_zb: function() {
        var articleid = detailData.id_3 + '_' + detailData.articletype;
        this.ajaxRequest(articleid, function(data) {
            data = data || [], $top = $('#interview .topPic');
            for(var i = 0; i < data.length; i++) {
                if(data[i].type == 'live') {
                    var map = {'1': {text: '未开始', cls: 'prepare'}, '2': {text: '直播中...', cls: 'living'}, '3': {text:'已结束', cls: 'over'}};
                    $top.find('.colTip').addClass(map[data[i].num+''].cls).html(map[data[i].num+''].text);

                }
                else if(data[i].type == 'join') {
                    $top.find('.count').html(data[i].num + ' 参与');
                }
            }
        });
    },
    /**异步请求数据*/
    ajaxRequest: function(articleid, success) {
        $.ajax({
            type: 'GET',
            url: this.ajaxUrl + articleid,
            dataType: 'json',
            success: function(json) {
                success(json.data);
            }
        });
    }
}
